<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Iqiyi extends CI_Controller {

	function __construct()
	{
		parent::__construct(); 
	}

 
	function fetch($id,$maxid=10)
	{
		if($id<=1000000){
			$id=$id+1000000;
		}
		$url="http://t.iqiyi.com/m/$id/detail";
		$data = array();
		// get url title
		$content = @file_get_contents($url);  
		if(strpos('showStarDetail',$content)>=0){ 
			 $content =str_replace("showStarDetail(","",$content);
			 $content =str_replace(");","",$content); 
			 $content = iconv('GB2312', 'UTF-8', $content);
			//$content=unicode_encode($content);
			 $star=json_decode($content);
			 //$data['celebid']= $star->id ;
			 $data['name']= $star->name ;
			 $data['cname']= $star->cname ;
			 $data['yname']= $star->yname ;
			 $data['first']= $star->first ;
			 $data['sex']= $star->sex ;
			 $data['country']= $star->country ;
			 $data['region']= $star->region ;
			 $data['work']= $star->work ;
			 $data['birthplace']= $star->birthplace ;
			 $data['birthday']= $star->birthday ;
			 $data['constellation']= $star->constellation ;
			 $data['blood']= $star->blood ;
			 $data['height']= $star->height ;
			 $data['weight']= $star->weight ;
			 $data['bwh']= $star->bwh ;
			 $data['company']= $star->company ;
			 $data['weibo']= $star->weibo ;
			 $data['memo']= $star->memo ;
			 $data['hotlogo']= $star->hotlogo ;
			 $data['detaillogo']= $star->detaillogo ;
			 $data['sourceurl']= $star->sourceurl ;
			 $data['hotsort']= $star->hotsort ;
			 $data['sort']= $star->sort ;
			 $data['mtagid']= $star->mtagid ;
			 
	        $query = $this->db->get_where('app_celeb',array('name' =>  $star->name));
	        $res=$query->result(); 
			 if(count($res)==0&&$star->name!=''){
			 	 $this->db->insert("app_celeb",$data);
			 }else{
			 }
			 //print_r($data);
			 if($id<=$maxid){
			 $data['nextid']=$id+1;
			 $data['maxid']=$maxid;
			 }
			 $this->smarty->view("star/fetch", $data); 
		}
	}


}
?>